﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using Ensemble2D.Forms;
using NLog;

namespace Ensemble2D
{
    static class Program
    {
        private const string EnsembleMainLicenseUrl = @"https://git.oschina.net/Esstudio/ensemble2d/blob/master/README.md";
        private static readonly Logger log = LogManager.GetCurrentClassLogger();
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            bool recover = false;
            foreach (var a in args)
            {
                if (a == "debug")
                {
                    Debugger.Launch();
                }else if (a == "recover")
                {
                    recover = true;
                }
            }

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            Application.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var splashScreen = new SplashScreen(recover);
            splashScreen.Show();
            Application.Run();
        }

        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            log.Error(e.Exception);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            log.Error(e.ExceptionObject as Exception);
        }
    }
}
